<?Lassoscript
// Last modified 2/24/11 by ECL, Landmann InterActive

// FUNCTIONALITY
// This file is called by urlhandler_atbegin.lasso (usually in the site's Lasso Startup folder)
// It does URL mapping to provide clean URLs

// TESTING
// Substitute ($vResponse_Filepath) for (Response_Filepath)

// Debugging
// DON'T use $svDebug, just enable the code that displays (Content_Body)

// USAGE NOTES
// IMPORTANT! This file must produce a $vID, or else output will go to default home page
// Need an Apache directive that handles extensionless files to get this to work

// FUNCTIONALITY OUTLINE
// 1. Get the whole heirarchy+content tree
// 2. Compare the Response_Filepath to the tree
// 3. Set the value of vID to be ContentID
// 4. Look up the RootID for the ContentID page. Used to control navigation panels show/hide.

// DEVELOPER'S NOTES
// Working model for this is in /devel/nestedset_viewSite.lasso

// CHANGE NOTES
// 2/24/11
// Reworked for v 4

// Check for devel site, look for leading "dev" in site name
Var('svIsDevelSite' = boolean);
(Server_Name)->(BeginsWith('dev')) ? $svIsDevelSite = true | $svIsDevelSite = false;

Include('/siteconfig.lasso');

// Initialize vars - DO NOT MOVE or .lasso pages will throw errors
Var('ContentIDMap' = map);
Var('ContentPathMap' = map);
Var('ContentHeadMap' = map);
Var('ContentHeirIDMap' = map);
Var('URLLabelMap' = (lp_array));

// Log_Critical('urlhandler: ' ($svDomain)' -- BEGIN Response_Filepath = ' (Response_Filepath));
// Log the URL Handler Request
Var('svLogFile' = '/logs/URLHandler.log');
/* Log($svLogFile);
	('urlhandler: '+($svDomain)+' -- Response_Filepath = '+(Response_Filepath)+'\n');
/Log;
*/
// Set $ProcessCleanURLs which controls whether or not to process this page with Clean URLS
Var('ProcessCleanURLs' = false);

// First look at detail.lasso
If((Response_Filepath)->endswith('/detail.lasso'));
	$ProcessCleanURLs = true;
// Next look at index.lasso
Else((Response_Filepath) == '/index.lasso');
	$ProcessCleanURLs = true;
// Is this a template rendering page?
Else((Response_Filepath) >> 'preview_template.lasso');
	$ProcessCleanURLs = false;
// Is this a template preview page?
Else((Response_Filepath) >> 'preview.lasso');
	$ProcessCleanURLs = false;
// Next look for any .lasso or .lassoapp file
Else((Response_Filepath)->endswith('.lasso') || (Response_Filepath)->endswith('.lassoapp'));
	$ProcessCleanURLs = false;
// php files
Else: (Response_Filepath)->(endswith:'.php');
	$ProcessCleanURLs = false;
// WordPress
Else: (Response_Filepath)->(endswith:'/blog/') || (Response_Filepath)->(endswith:'/wp-admin/') || (Response_Filepath)->(endswith:'.php');
	$ProcessCleanURLs = false;
// Finally catch everything else
Else;
	$ProcessCleanURLs = true;
/If;

// REDIRECTS

// Intercept request for admin or login pages.
If(
	(Response_Filepath)->endswith('/admin/') ||
	(Response_Filepath)->endswith('/admin') ||
	(Response_Filepath)->endswith('/admin/login') ||
	(Response_Filepath)->endswith('/login/') ||
	(Response_Filepath)->endswith('/login')
	);

	(Content_Body) = include('/app/modules/admin/controllers/login.lasso');
	LI_CMSatend;
	Abort;

// Logout
Else(
	(Response_Filepath)->endswith('/admin/logout') ||
	(Response_Filepath)->endswith('/logout/') ||
	(Response_Filepath)->endswith('/logout')
	);

	(Content_Body) = include('/app/modules/admin/controllers/login.lasso?Action=logout');
	LI_CMSatend;
	Abort;

/If;

// Build the heirarchy maps
// Need to do this REGARDLESS of whether it's a clean URL, so generate_google_sitemap.lasso functions
Include(($svBaseHelpersPath)+'build_heirmaps.inc');

// Log Request
// Log_Critical('urlhandler 46: '+($svDomain)+' -- BEGIN Response_Filepath = '+(Response_Filepath)+' $vID = '+($vID));

// Process the Clean URLs page
If($ProcessCleanURLs == true);

	// Run site - Use absolute path!
	(Content_Body) = Include('/detail.lasso');
	LI_CMSatend;
	Abort;

/If;

?>
